package com.sxbdjw.situation.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.sxbdjw.situation.core.GWSDKManager;
import com.sxbdjw.situation.core.config.DeviceConfig;


public class KeyReceiver extends BroadcastReceiver {

    private static boolean keyDown = false;

    private void log(String msg){
        Log.d("KeyReceiver", this.getClass().getSimpleName()+"="+msg);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Bundle bundle = intent.getExtras();
        log("recv action="+action);
        if (keyDown) {
            if (GWSDKManager.getSdkManager().isOnline()) {
                GWSDKManager.getSdkManager().startSpeak();
            }
        }  else {
            if (GWSDKManager.getSdkManager().isOnline()) {
                GWSDKManager.getSdkManager().stopSpeak();
            }
        }
        keyDown = !keyDown;
    }
}
